home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / dviware / dvibook / libtex / dvistate.h < prev    next >
C/C++ Source or Header  |  1994-03-18  |  3KB  |  113 lines

  1. /*
  2.  * Copyright (c) 1989 University of Maryland
  3.  * Department of Computer Science.  All rights reserved.
  4.  * Permission to copy for any purpose is hereby granted
  5.  * so long as this copyright notice remains intact.
  6.  */
  7.  
  8. /* DVI file information (as used by dvi-to-device programs) */
  9.  
  10. /*
  11.  * Units of distance are stored in scaled points, but we can convert to
  12.  * units of 10^-7 meters by multiplying by the numbers in the preamble.
  13.  * The values hh and vv are kept in device coordinates.
  14.  */
  15.  
  16. /* the structure of the stack used to hold the values (h,v,hh,vv,w,x,y,z) */
  17. typedef struct dvi_stack {
  18.     i32    h;        /* the saved h */
  19.     i32    v;        /* the saved v */
  20.     i32    hh;        /* the saved hh */
  21.     i32    vv;        /* the saved vv */
  22.     i32    w;        /* etc */
  23.     i32    x;
  24.     i32    y;
  25.     i32    z;
  26. } DviStack;
  27.  
  28. /*
  29.  * DVI state machine interpreter encapsulation (global state).
  30.  */
  31. struct dvi_state {
  32.     /*
  33.      * Variables that must be set by user before calling SetDVIState().
  34.      */
  35.     int    ds_usermag;    /* user-supplied (additional) magnification */
  36.     int    ds_maxdrift;    /* maximum drift, typically 3 */
  37.  
  38.     /* the rest are set by DVISetState() */
  39.  
  40.     /*
  41.      * Values based on the (postamble of the) DVI file,
  42.      * or used by the interpreter.
  43.      */
  44.     i32    ds_num;        /* numerator from DVI file */
  45.     i32    ds_denom;    /* denominator from DVI file */
  46.     i32    ds_dvimag;    /* magnification from DVI file */
  47.     i32    ds_maxheight;    /* height of tallest page */
  48.     i32    ds_maxwidth;    /* width of widest page */
  49.     i32    ds_prevpage;    /* previous page of DVI file */
  50.     int    ds_npages;    /* number of DVI pages */
  51.     DviStack *ds_stack;    /* base of stack of DVI values */
  52.     DviStack *ds_sp;    /* current place in stack */
  53.     DviStack ds_cur;    /* current values */
  54.     DviStack ds_fresh;    /* fresh values for new pages: not all
  55.                    zero unless there are no margins.
  56.                    This works because all DVI motion
  57.                    is relative. */
  58.     /*
  59.      * Although this is not strictly within the realm of DVI
  60.      * state, we need a place to store the fonts we allocate
  61.      * while reading through the postamble.  Each entry in
  62.      * the ds_fonts search table is a pointer to a font,
  63.      * so that *(struct font **)SSearch(...) is the pointer.
  64.      */
  65.     struct    search *ds_fonts;/* font table */
  66.  
  67.     /*
  68.      * A few routines want a private copy of the DVI file pointer.
  69.      */
  70.     FILE    *ds_fp;        /* input DVI file */
  71. };
  72.  
  73. extern struct dvi_state ds;
  74.  
  75. /* shorthand */
  76. #define    dvi_h    ds.ds_cur.h
  77. #define    dvi_v    ds.ds_cur.v
  78. #define    dvi_hh    ds.ds_cur.hh
  79. #define    dvi_vv    ds.ds_cur.vv
  80. #define    dvi_w    ds.ds_cur.w
  81. #define    dvi_x    ds.ds_cur.x
  82. #define    dvi_y    ds.ds_cur.y
  83. #define    dvi_z    ds.ds_cur.z
  84.  
  85. /*
  86.  * Set up the state for the interpreter loop.
  87.  */
  88. void DVISetState();
  89.  
  90. /*
  91.  * Service routines (called from main loop).
  92.  */
  93. struct font *DVIFindFont();
  94. void DVIRule(), DVIBeginPage();
  95.  
  96. /*
  97.  * Drift fixing.  Note that the first argument must be an lvalue.
  98.  * It is the desired position in pixels, and is maintained within
  99.  * ds.ds_maxdrift pixels of the second argument, which is the
  100.  * `absolute' DVI position rounded to the nearest pixel.
  101.  */
  102. #define    FIXDRIFT(xx, x) \
  103.     if ((x) >= (xx)) \
  104.         if ((x) - (xx) <= ds.ds_maxdrift) \
  105.             /* position is in bounds */; \
  106.         else \
  107.             (xx) = (x) - ds.ds_maxdrift; \
  108.     else \
  109.         if ((xx) - (x) <= ds.ds_maxdrift) \
  110.             /* position is in bounds */; \
  111.         else \
  112.             (xx) = (x) + ds.ds_maxdrift
  113.